﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PhoneStore.Entity;

namespace PhoneStore.Presentation.CompositeControl
{
    /// <summary>
    /// Interaction logic for BillListTab.xaml
    /// </summary>
    public partial class BillListTab : BaseUserControl
    {
        public BillListTab()
        {
            InitializeComponent();
            ucList.SetUp(EnableEditItemFunc, true, CheckError);
            txtBillID.IsEnabled = false;
            cbbCustomer.IsEditable = true;
        }

        protected string CheckError()
        {
            string errors = "";
            if (cbbStaff.SelectedItem == null)
            {
                errors += "-Nhân viên bán hàng không được trống\n";
            }
            if (String.IsNullOrEmpty(dpSellDate.Text))
            {
                errors += "-Ngày bán hàng không được trống\n";
            }

            return errors;
        }

        protected override void SetUpComboBox()
        {
            cbbCustomer.ItemsSource = DAO.GetAll<Customer>().Select(x=> new {Value = x.PersonID,Text = x.Fullname});
            cbbCustomer.SelectedValuePath = "Value";
            cbbCustomer.DisplayMemberPath = "Text";
            
            cbbStaff.ItemsSource = DAO.GetAll<Staff>().Select(x=> new {Value = x.ID,Text = x.Fullname});
            cbbStaff.SelectedValuePath = "Value";
            cbbStaff.DisplayMemberPath = "Text";
        }

        protected override void EnableEditItemFunc(bool value)
        {
            cbbStaff.IsEnabled = cbbCustomer.IsEnabled =
                 dpSellDate.IsEnabled = value;
        }

        private void btnEditDetail_Click(object sender, RoutedEventArgs e)
        {
            if (ucList.SelectedItem != null)
            {
                
                BillDetailListWindow w = new BillDetailListWindow(ucList.SelectedItem.BillID);
                w.ShowDialog();
            }
            else
            {
                MessageBox.Show("Hãy Chọn Hóa đơn để sửa");
            }
        }
    }
}
